package juc.juccore.threadlocal;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 将线程不安全的threadlocal类转换为线程安全的工具类
 */
public class ThreadLocalNormalUsage01 {
    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i < 30; i++) {
            int a = i;
            new Thread(() -> {
                String data = new ThreadLocalNormalUsage01().data(a * 10);
                System.out.println(data);
            }).start();
            TimeUnit.SECONDS.sleep(1);
        }
    }

    public String data(int seconds) {
        Date date = new Date(1000 * seconds);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(date);
    }

}
